package com.jy.rhin.facade.infra.controller.notification.assembler;

import com.jy.rhin.domain.notification.subscribe.entity.vo.SubscribeTopicFilterVO;
import com.jy.rhin.sdk.dto.notification.BusinessSubscribeTopicDto;
import com.jy.rhin.sdk.dto.notification.SubscribeTopicDto;
import com.jy.rhin.sdk.dto.notification.SubscribeTopicFilterDto;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author WeiQ
 * @date 2022/6/28 10:58
 * 主题订阅dto转换器
 */
public class SubscribeTopicAssembler {

    private SubscribeTopicAssembler() {
    }


    public static List<SubscribeTopicFilterVO> toFilterVO(List<SubscribeTopicFilterDto> filterList) {
        if (!CollectionUtils.isEmpty(filterList)) {
            return filterList.stream().map(subscribeTopicFilter -> {
                SubscribeTopicFilterVO filterVo = new SubscribeTopicFilterVO();
                filterVo.setQueryFilterExp(subscribeTopicFilter.getFilterExp());
                filterVo.setQueryFilterValue(subscribeTopicFilter.getValue());
                return filterVo;
            }).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList());
        }
        return Collections.emptyList();
    }

    public static SubscribeTopicDto toSubscribeTopicDto(BusinessSubscribeTopicDto subscriberTopic,
                                                        String subscriberCode,
                                                        String operator) {
        SubscribeTopicDto subscribeTopicDto = new SubscribeTopicDto();
        BeanUtils.copyProperties(subscriberTopic, subscribeTopicDto);
        subscribeTopicDto.setSubscriberCode(subscriberCode);
        subscribeTopicDto.setOperator(operator);
        return subscribeTopicDto;
    }

}
